package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialBalancedeadlineService;
import com.ph.irp.model.PBaseAssistantmaterialBalancedeadline;

public class AssistantmaterialBalanceDeadlineAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4369370499139039411L;
	// 结算期限service
	private PBaseAssistantmaterialBalancedeadlineService deadlineService;
	// 结算期限list
	private List<PBaseAssistantmaterialBalancedeadline> deadlineList;
	// 结算期限model
	private PBaseAssistantmaterialBalancedeadline balancedeadline;

	// 接收选中复选框传递的数据
	private String[] rowlist = null;
	private String FORWARD;

	public String getDeadlines() throws Throwable {
		if (balancedeadline == null)
			deadlineList = deadlineService.getAllBalancedeadlines();
		else if (!balancedeadline.getBalanceDeadLineCode().trim().equals("")
				&& !balancedeadline.getBalanceDeadLineName().trim().equals(""))
			deadlineList = deadlineService.getBalancedeadlinesByCodeAndName(
					balancedeadline.getBalanceDeadLineCode(), balancedeadline
							.getBalanceDeadLineName());
		else if (!balancedeadline.getBalanceDeadLineCode().trim().equals(""))
			deadlineList = deadlineService
					.getBalancedeadlinesByCode(balancedeadline
							.getBalanceDeadLineCode());
		else if (!balancedeadline.getBalanceDeadLineName().trim().equals(""))
			deadlineList = deadlineService
					.getBalancedeadlinesByName(balancedeadline
							.getBalanceDeadLineName());
		else
			deadlineList = deadlineService.getAllBalancedeadlines();
		balancedeadline = null;
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 新增结算期限
	 * 
	 * @return
	 * @throws Throwable
	 */
	public String addDeadline() throws Throwable {
		deadlineService.addBalancedeadline(balancedeadline);
		balancedeadline = null;

		FORWARD = "success";
		return FORWARD;

	}

	/**
	 * 更新结算期限
	 * 
	 * @return
	 * @throws Throwable
	 */
	public String updateDeadlineInput() throws Throwable {

		int deadlineId = Integer.valueOf(rowlist[0]);
		balancedeadline = deadlineService.getBalancedeadlineById(deadlineId);
		FORWARD = "success";
		return FORWARD;
	}

	public String updateDeadline() throws Throwable {
		deadlineService.updateBalancedeadline(balancedeadline);
		balancedeadline = null;
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 删除辅助物料结算期限
	 * 
	 * @return
	 */
	public String deleteDeadline() throws Throwable {

		// 批量删除结算期限
		deadlineService.deleteBalancedeadline(rowlist);
		balancedeadline = null;
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * 选择辅助物料结算期限
	 * 
	 * @return
	 */
	public String selectDeadline() throws Throwable {
		this.getDeadlines();
		balancedeadline = null;
		FORWARD = "success";
		return FORWARD;
	}
	
	public String showDeadlineList() throws Throwable {
		balancedeadline = null;
		this.getDeadlines();
		FORWARD = "success";
		return FORWARD;
	}

	/**
	 * getters and setters for instance variables
	 * 
	 * @return
	 */

	public PBaseAssistantmaterialBalancedeadlineService getDeadlineService() {
		return deadlineService;
	}

	public void setDeadlineService(
			PBaseAssistantmaterialBalancedeadlineService deadlineService) {
		this.deadlineService = deadlineService;
	}

	public List<PBaseAssistantmaterialBalancedeadline> getDeadlineList() {
		return deadlineList;
	}

	public void setDeadlineList(
			List<PBaseAssistantmaterialBalancedeadline> deadlineList) {
		this.deadlineList = deadlineList;
	}

	public PBaseAssistantmaterialBalancedeadline getBalancedeadline() {
		return balancedeadline;
	}

	public void setBalancedeadline(
			PBaseAssistantmaterialBalancedeadline balancedeadline) {
		this.balancedeadline = balancedeadline;
	}

	public String[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(String[] rowlist) {
		this.rowlist = rowlist;
	}

}
